package com.cheng.mybatis02.service.impl;

import com.cheng.mybatis02.dao.UserMapper;
import com.cheng.mybatis02.entity.User;
import com.cheng.mybatis02.service.UserService;

import java.util.Map;

public class UserServiceImpl implements UserService {
    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User findUserById(int id) {
        return userMapper.queryUserById(id);
    }

    @Override
    public User login(String username, String password) {
        return userMapper.queryUserByUsernameAndPassword(username,password);
    }

    @Override
    public User findUserByIdAndUsername(Map<String, String> params) {
        return userMapper.queryUserByIdAndUsername(params);
    }

    @Override
    public int addUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public int removeUser(int id, String username) {
        return userMapper.deleteUser(id,username);
    }
}
